package com.iplant.wms.serviceImpl.dao.brm;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.base.utils.annotation.dao.DBBaseDAO;
import com.iplant.base.utils.sql.BaseDAO;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.wms.service.po.brm.BRMSerialNoRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

@DBBaseDAO(BRMSerialNoRule.class)
public class BRMSerialNoRuleDAO extends BaseDAO {

    private static BRMSerialNoRuleDAO Instance = null;
    private static Logger logger = LoggerFactory.getLogger(BRMSerialNoRuleDAO.class);

    private BRMSerialNoRuleDAO() {
        super("");
        this.Init();
    }

    public static BRMSerialNoRuleDAO getInstance() {
        if (Instance == null) {
            Instance = new BRMSerialNoRuleDAO();
        }
        return Instance;
    }


    public void BRM_DeleteSerialNoRule(BMSEmployee wLoginUser, BRMSerialNoRule wSerialNoRule, OutResult<Integer> wErrorCode) {
        wErrorCode.set(0);

        try {
            if (wSerialNoRule == null || wSerialNoRule.ID <= 0) {
                wErrorCode.set(ExceptionTypes.Parameter.getValue());
                return;
            }
            int wRows = this.DeletePO(wLoginUser, wSerialNoRule, wErrorCode);

            if (wRows > 0) {
                BRMSerialNoRangeDAO.getInstance().BRM_DeleteSerialNoRange(wLoginUser, wSerialNoRule.ID, wErrorCode);
            }

        } catch (Exception ex) {
            wErrorCode.set(ExceptionTypes.DBSQL.getValue());
            logger.error("BRM_UpdateSerialNoRule", ex);
        }
    }


    public List<BRMSerialNoRule> BRM_QuerySerialNoRuleList(
            BMSEmployee wLoginUser, String wName,
            int wActive, Pagination wPagination, OutResult<Integer> wErrorCode) {
        Map<String, Object> wParams = new HashMap<String, Object>();


        wParams.put("Name", wName);
        wParams.put("Active", wActive);

        return super.SelectPOList(wLoginUser, wParams, wPagination, wErrorCode);

    }


}
